const lark = require("@larksuiteoapi/node-sdk");
var axios = require("axios");


//更改对应的app_id
const FEISHU_APP_ID = "cli_a5353776bba9100d";
const FEISHU_APP_SECRET = "nSNp3X7T6NWgP7kkY3Rt9dGJpfjBbPcR";


// 日志辅助函数，请贡献者使用此函数打印关键日志
function logger(param) {
    console.warn(`[CF]`, param);
}


const client = new lark.Client({
    appId: FEISHU_APP_ID,
    appSecret: FEISHU_APP_SECRET,
    disableTokenCache: false,
    appType: lark.AppType.SelfBuild,
    domain: lark.Domain.Feishu,
});


// 回复消息
async function create(chat_id, content) {
    console.log("create", chat_id + " " + content);
    try {
        return await client.im.message.create({
            data: {
                receive_id: chat_id,
                content: JSON.stringify({
                    text: content,
                }),
                msg_type: "text",
            },
            params: {
                receive_id_type: "chat_id"
            }
        });
    } catch (e) {
        logger("send message to feishu error", e, receive_id, content);
    }
}


console.log("发送文本消息-start");

async function executeAsyncFunction002() {
    try {
        const result = await create("oc_eaa5a9a1de79f3ebe01d605feddebfd9", "ssss")
        console.log(result); // 输出 'Hello World'
    } catch (error) {
        console.error(error);
    }
}

executeAsyncFunction002()
console.log("发送文本消息-end");
